# -*- coding: utf-8 -*-
"""
-------------------------------------------------
  File Name：   main
  Description :
  Author :    崔术森
  Eamil  :    deer_cui@163.com
  date：     2021/11/05
-------------------------------------------------
  Change Activity:
          2021/11/05:
-------------------------------------------------
"""
__author__ = '崔术森'

import json
import os
import sys

from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication
from controller.controller_main import controller_main
from cfg.cfg import CFG
if __name__ == "__main__":
    try:
        app = QApplication(sys.argv)
        # 设置按钮样式表
        historyData = None
        userSkinPath = "darkstyle.qss"
        skinSendStyle = ""
        with open(os.getcwd() + "/history.json", "r", errors="ignore", encoding="utf-8") as f:
            historyData = json.load(f)
        if historyData is not None:
            userSkin = historyData["skin"]
            skinSendStyle = historyData["skinSendStyle"]
            if userSkin == 0:
                userSkinPath = "lightstyle.qss"
        with open("./stylesheets/%s"%userSkinPath, "r", encoding="utf-8") as f:
            app.setStyleSheet(f.read())
        mainForm = controller_main()
        mainForm.skin = userSkin
        mainForm.cfg.sendTitleColor = skinSendStyle["sendTitleColor"]
        mainForm.cfg.sendContentColor = skinSendStyle["sendContentColor"]
        mainForm.cfg.recColor_R = skinSendStyle["recColor_R"]
        mainForm.cfg.recColor_G = skinSendStyle["recColor_G"]
        mainForm.cfg.recColor_B = skinSendStyle["recColor_B"]
        mainForm.show()
        sys.exit(app.exec_())
    except Exception as e:
        print(e)
